#ifndef CEPOLLWORKTHREAD_H
#define CEPOLLWORKTHREAD_H

#include <QObject>
#include <QRunnable>
#include <QByteArray>
#include <QDebug>

#include <unistd.h>
#include <netinet/tcp.h>

#include "tcpstruct.h"
#include "ctagdata.h"

#define DEF_TEMP_MAX 4096

class CClientData;

class CEpollWorkThread : public QObject, public QRunnable
{
    Q_OBJECT
public:
    explicit CEpollWorkThread(int nSocketFd);
    void run() override;
    //设置客户端信息
    inline void setClientConfig(SClientCfg stCfg) { m_stCfg = stCfg; }
    //设置客户端测点信息
    inline void setClientData(CClientData* pClient) { m_pClient = pClient; }

private:
    //读取数据
    bool readData(QByteArray& szBuffer);

signals:
    //运行日志
    void sigRunningLogMsg(const int&, const int&, const QString&, const QString&);
    //测点信息变更 入参
    void sigTagsInfoChanged(const int& nFd, const QString& sTagsInfo, int nCurNum, int TotalNum, int nRemainNum);
    //客户端连接关闭
    void sigConnectionClosed(int nFd);
    //报警信息
    void sigWarningMSg(const QString&, const QString&);
    //客户端日志信息
    void sigClientLogMsg(const QString&, const QString&);

public slots:
    //返回解析结果
    bool slotHandleRecvStatus(bool bRtn);

public:
    bool                m_bConnected;

private:
    int                 m_nSocketFd;
    SClientCfg          m_stCfg;
    CClientData*        m_pClient;
    quint8              m_nReplyByte0;
    quint8              m_nReplyByte1;
};

#endif // CEPOLLWORKTHREAD_H
